package com.xwj.controller;

import com.xwj.common.dto.BaseResponse;
import com.xwj.dto.UserAccountDto;
import com.xwj.service.ZookeeperLockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xwj
 * @date 2020/5/6
 */
@RestController
@RequestMapping("/zookeeper/lock/")
public class ZookeeperLockController {
    @Autowired
    private ZookeeperLockService zookeeperLockService;

    /**
     * 使用zookeeper分布式锁
     * @param dto
     * @return
     */
    @GetMapping("/takeMoneyZookeeperLock")
    public BaseResponse takeMoneyZookeeperLock(@Validated UserAccountDto dto) {
        try {
            zookeeperLockService.takeMoneyZookeeperLock(dto);
            return BaseResponse.success();
        } catch (Exception e) {
            return BaseResponse.error(e.getMessage());
        }
    }

}
